﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="printablepage.aspx.cs" Inherits="IGIS.printablepage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <link href="../styles/geomapper.css" rel="stylesheet" type="text/css">
      <title>GeoMapper - %s</title>
    <style type="text/css">
    div
    {
        font-family: __#@font#__;
        font-size:11px;
        background-color: #f5f5f5
    }
    td.Title
    {
        font-family: __#@font#__;
        font-size:22px;
        font-weight:bold;
        width: 50%;
    }
    td.net
    {
      font-size:1px;
      border-bottom: 1px solid #dcdcdc;
      border-left: 1px solid #dcdcdc;
      width: 100;
    }
	#Minimap
	{
		width:150px;
		height:130px;
		background-image:url('%s');
		background-repeat:none;
		backgorund-position:center;
		background-color:#FFFFFF;
		border:solid 1px Silver;
		margin:0 3px 0 3px;
	}
	#MinimapTitle
	{
		width:150px;
		background-color:#FFFFFF;
		border:solid 1px Silver;
		border-bottom: none;
		margin:0 3px 0 3px;
		text-align:Center;
	}
        
    </style>
    <script language="javascript" src="Scripts/browserdetect.js"></script>
    <script language="javascript" src="Scripts/legendbuilder.js"></script>
    <script language="javascript" src="Scripts/json2.js"></script>
        <script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>
    <script language="javascript" type="text/javascript">
    /*debugger;*/
      var webAgent = "/mapserver2012/mapagent/mapagent.fcgi";
      var scale = <%=scale %>;
      var centerX = <%=centerX %>;
      var centerY = <%=centerY %>;
      var dpi = <%=dpi %>;   
        
      var mapName = '<%= mapName%>';
      var sessionId = '<%=sessionId %>';
  	  var hideLayer ="";
      // '%s'; //Added for minimap script
      var isTitle =<%=isTitle %> , isLegend =  <%=isLegend %>,  isMinimap = <%=isMinimap %>, isArrow    =  <%=isArrow %>,  isLogo = <%=isLogo %>;
      var isFrame = <%=isFrame %>, netType  = '<%=netType%>', PaperSize = <%=prSize %>, PaperScale = '<%=prScale%>', Orientation = '<%=prOrientation %>';
      var jsonLegend = '<%=getGetLegendInfo %>';
      var msg_changepapre = 'A'+PaperSize+' בחר/י מדפסת וגודל דף מתאים ל';
      var tdh;
      var tdw;

      function InitDocument(){
     
      var PaperWidth;
      var mapWidth;
      var mapHeight;
      var ScaleImg;

      if(PaperSize=='4'){
      pw = (Orientation == 'portrait' ? 700 : 1000); mw = (Orientation == 'portrait' ? 480 : 780);
      mh = (Orientation == 'portrait' ? 850 : 550);  si =  (Orientation == 'portrait' ? 350 : 900);
      imgw = (Orientation == 'portrait' ? 135 : 210);  imgh = (Orientation == 'portrait' ? 162 : 85);
      aw = (Orientation == 'portrait' ? 'a4w_p' : 'a4w_l');  ah = (Orientation == 'portrait' ? 'a4h_p' : 'a4h_l');
      }
      if(PaperSize=='3'){
      pw = (Orientation == 'portrait' ? 1000 : 1500); mw = (Orientation == 'portrait' ? 780 : 1280);
      mh = (Orientation == 'portrait' ? 1300 : 850);  si =  (Orientation == 'portrait' ? 650 : 1500);
      imgw = (Orientation == 'portrait' ? 230 : 330);  imgh = (Orientation == 'portrait' ? 275 : 160);
      aw = (Orientation == 'portrait' ? 'a3w_p' : 'a3w_l');  ah = (Orientation == 'portrait' ? 'a3h_p' : 'a3h_l');
      }
      if(PaperSize=='2'){
      pw = (Orientation == 'portrait' ? 1500 : 2100); mw = (Orientation == 'portrait' ? 1280: 1880);
      mh = (Orientation == 'portrait' ? 2000 : 1300);  si =  (Orientation == 'portrait' ? 1100 : 1700);
      imgw = (Orientation == 'portrait' ? 335 : 480);  imgh = (Orientation == 'portrait' ? 450 : 275);
      aw = (Orientation == 'portrait' ? 'a2w_p' : 'a2w_l');  ah = (Orientation == 'portrait' ? 'a2h_p' : 'a2h_l');
      }

      if(PaperSize=='1'){
      pw = (Orientation == 'portrait' ? 2100 : 3000); mw = (Orientation == 'portrait' ? 1880 : 2780);
      mh = (Orientation == 'portrait' ? 2600 : 1800);  si =  (Orientation == 'portrait' ? 2400 : 2500);
      imgw = (Orientation == 'portrait' ? 480 : 710);  imgh = (Orientation == 'portrait' ? 620 : 400);
      aw = (Orientation == 'portrait' ? 'a1w_p' : 'a1w_l');  ah = (Orientation == 'portrait' ? 'a1h_p' : 'a1h_l');
      }

      if(PaperSize=='0'){
      pw = (Orientation == 'portrait' ? 2900 : 4300); mw = (Orientation == 'portrait' ? 2680 : 4080);
      mh = (Orientation == 'portrait' ? 4200 : 2900);  si =  (Orientation == 'portrait' ? 2500 : 3800);
      imgw = (Orientation == 'portrait' ? 680 : 1040);  imgh = (Orientation == 'portrait' ? 1000 : 670);
      aw = (Orientation == 'portrait' ? 'a0w_p' : 'a0w_l');  ah = (Orientation == 'portrait' ? 'a0h_p' : 'a0h_l');
      }

     PaperWidth=pw; mapWidth=mw; mapHeight=mh; ScaleImg=si; tdh=ah; tdw=aw;
      imgpixelw = new String(imgw);
      imgpixelh = new String(imgh);

      document.getElementById("toc").style.width = PaperWidth;
      
      if(!isTitle){
      document.getElementById("Title").style.height = "0px";
      mapHeight += 27;
      }else{
      document.getElementById("tblTitle").style.width = PaperWidth; //document.body.clientWidth-10;
      }

      //else
          mapWidth += 180;

      if(!isArrow){
          mapHeight += 58;
          document.getElementById("ScaleAndArrow").style.height = "0px";
      }
     //debugger;
      Builed_OuterMapNet(netType, PaperSize, Orientation);
      var mapTop = document.getElementById("Map-top");       mapTop.style.width = mapWidth + "px";
      var mapBottom = document.getElementById("Map-bottom"); mapBottom.style.width = mapWidth + "px";
      var mapLeft = document.getElementById("Map-left");     mapLeft.style.height = mapHeight + "px";
      var mapRight = document.getElementById("Map-right");   mapRight.style.height = mapHeight + "px";
      //debugger;
      var mapElt = document.getElementById("map");
      mapElt.style.width = mapWidth + "px";
      mapElt.style.height = mapHeight + "px";

      var legendElt = document.getElementById("Legend");
      //legendElt.style.width = mapWidth;
      if(isLegend){
          legendElt.style.height = "145px";
		  var legendInfo = JSON.parse(jsonLegend);
          legendElt.innerHTML = builedlagend(legendInfo, PaperSize)
      }else
        legendElt.innerHTML = "<textarea style='border:none 0px #ffffff' cols=25 rows=7></textarea>"

	  var minimapElt = document.getElementById("MinimapContainer");
      if(isMinimap == 0){
		minimapElt.style.display = 'none';
	  }
     /* if(isArrow)
          document.getElementById("Arrow").innerHTML = "<br><img src=\"../stdicons/HetzSmall.png\" style=''>";*/

       //if(isScale)
         var scl = parseInt(PaperScale);
         var when = new Date();
         var scalesec = document.getElementById(compactFooter ? "Logo" : "Scale");
		 document.getElementById("Scale").style.display = compactFooter ? "none" : "block";
         
         var scaletable = "<div id='scaleTable' style='background-color:#FFF;text-align:center'><br><u>קנ''מ: " + scl+ "    :1"+"</u><br>" +
        "<table dir=rtl cellpadding=0 cellspacing=0 style='border: solid 1px silver; width:140px;font-size:8px;text-align:center'>" +
            "<tr style='height: 7px;'><td style='background-color:Blue; width:60px; color: White'>4 סמ</td><td style='width:60px; color: blue'>3 סמ</td><td style='background-color:Blue; width:60px; color: White'>2 סמ<td style='width:60px; color: blue'>1 סמ</td></tr>" +
        "</table>" +
        "<table dir=ltr cellpadding=0 cellspacing=0 style='border: solid 0px silver; width:160px;font-size:9px;text-align:right'>" +
        "<tr style='height: 10px;'>"
        if(scl >= 100)
        {
            scaletable += "<td style='width:30px;'>0 מטר</td><td style='width:30px'>" + Math.floor(scl/100) +
            "</td><td style='width:40px;'>" + 2*Math.floor(scl/100) +
            "<td style='width:40px;'>" + 3*Math.floor(scl/100) +
            "</td><td style='width:40px;'>" + 4*Math.floor(scl/100) + "</td></tr>"
        }
        else
        {
            scaletable += "<td style='width:30px;'>0 מטר</td><td style='width:30px'>" + (scl/100) +
            "</td><td style='width:40px;'>" + 2*(scl/100) +
            "<td style='width:40px;'>" + 3*(scl/100) +
            "</td><td style='width:40px;'>" + 4*(scl/100) + "</td></tr>"
        }
        scaletable += "</table></div>"
        
         scalesec.innerHTML = scaletable;
		 //document.getElementById("footerTable").style.width=mapWidth;
         //scalesec.style.width=mapWidth; //ScaleImg;

        if(isLogo) {
          document.getElementById("Logo").innerHTML = "<img id='imgLogo' src=\"images/negevlogo.jpg\" style='width:250px;display:"+(isLogo ? 'block' : 'none')+"';>"+document.getElementById("Logo").innerHTML+"הופק  ב: "+when.toLocaleDateString()
        }
		else {
			document.getElementById("Logo").style.display = "none";
			document.getElementById("Scale").style.display = "none";
		}		
          
          var requester;
          if(msie)
              requester = new ActiveXObject("Microsoft.XMLHTTP");
          else
              requester = new XMLHttpRequest();
             // debugger;
          var reqParams = "OPERATION=GETVISIBLEMAPEXTENT&VERSION=2.0.0&MAPNAME=" + encodeURIComponent(mapName) + "&SESSION=" + sessionId + "&SETDISPLAYWIDTH=" + mapWidth + "&SETDISPLAYHEIGHT=" + mapHeight + "&SETDISPLAYDPI=" + dpi + "&SETVIEWSCALE=" + PaperScale + "&SETVIEWCENTERX=" + centerX + "&SETVIEWCENTERY=" + centerY + "&SEQ=" + Math.random();
		  //reqParams += "&HIDELAYERS=" + hideLayer; *///Added for minimap script
          //debugger;
		  requester.open("POST", webAgent, false);
          requester.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
          requester.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
		  requester.send(reqParams);

          if(requester.responseXML){
            if(ValidateMapResponse(requester.responseXML.documentElement)){
            var xmlRoot =requester.responseXML.documentElement;
                  /*var xs = xmlRoot.getElementsByTagName("X");
        var ys = xmlRoot.getElementsByTagName("Y");*/
              //  var im = webAgent + "?OPERATION=GETMAPIMAGE&VERSION=2.0.0&SELECTION=&FORMAT=JPG&MAPNAME=" + encodeURIComponent(mapName) + "&SESSION=" + sessionId +"&SEQ=" + Math.random();


                var im = webAgent +"?OPERATION=GETMAPIMAGE&VERSION=1.0.0&SESSION="+ sessionId+"&MAPNAME="+encodeURIComponent(mapName)+"&FORMAT=JPG&SETVIEWCENTERX="+centerX+"&SETVIEWCENTERY="+centerY+"&SETVIEWSCALE="+scale+"&SETDISPLAYHEIGHT=" + mapHeight + "&SETDISPLAYDPI=" + dpi + "&SETVIEWSCALE=" + scale + "&SETVIEWCENTERX=" + centerX + "&SETVIEWCENTERY=" + centerY + "&SEQ=" + Math.random();
                //&SHOWLAYERS=bbe737da-34a5-11e2-8000-000c294ca3a6_en_7F0000010B060B050B04
	  	//prompt("",im);
                mapElt.style.backgroundImage="url('"+im+"')";
             }
           }
        }


        function OnImageLoaded(id){
           document.getElementById(id).style.visibility = "visible";
        }
                
       // =================================================================================================================
       function printWindow() {
        
         if (!factory.object) {
            //Check OS Measure Units
            setMeasureUnits();
            //Install MedCo
            document.getElementById("installFailure").style.display = "block";
            return
          } else {
            document.getElementById("installFailure").style.display = "none";
           factory.printing.header = "";
            factory.printing.footer = "GeoMapper";
            factory.printing.portrait = (Orientation == 'portrait' ? true : false);
            factory.printing.leftMargin = 10.0;
            factory.printing.topMargin = 10.0;
            factory.printing.rightMargin = 10.0;
            factory.printing.bottomMargin = 10.0;
            //factory.printing.Print(true);
            //factory.printing.Preview()
            if(PaperSize!='4'){
              alert(msg_changepapre);
              factory.printing.PageSetup();
              }
            }
            
        }

        function setMeasureUnits(){
          var msg = '========================================================='+
                    'לאישור התאמת יחידות המדידה המוגדרות במחשב.\n\n'+
                    '========================================================='+
                    'להתאמת יחידות המדידה למטריות,\n'+
                    'לוח בקרה > הגדרות אזוריות > ...שיטת מדידה - מטרית'
          if(confirm(msg)){
            window.open('../vbscript/geomapper.vbs');
            return true
          }else
            return false
        }
 $(document).ready(function() {
  // Handler for .ready() called.
  /*alert("document ready");*/
  InitDocument();
  printWindow();

    });
   </script>

       
    </head>
  <body dir="rtl" style="overflow:scroll;overflow-x:hidden;
    SCROLLBAR-FACE-COLOR: #ffffff;SCROLLBAR-HIGHLIGHT-COLOR: #ffffff;SCROLLBAR-SHADOW-COLOR: #ffffff;SCROLLBAR-3DLIGHT-COLOR: #ffffff;SCROLLBAR-TRACK-COLOR: #ffffff;SCROLLBAR-DARKSHADOW-COLOR: #ffffff;SCROLLBAR-BASE-COLOR: #ffffff"  topmargin="5" bottommargin="5"  leftmargin="5" rightmargin="5" marginwidth="5" marginheight="5">
    <!-- MeadCo ScriptX -->
   <object id="factory" style="display:none"
      classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814"
      codebase="/negevgaz/scripts/smsx.cab#Version=6,3,435,20">
    </object>
   <div dir="rtl"  id="installFailure">
	    <h2>הגדרה אוטומטית של פרופיל הדפסה אינה אפשרית</h2>
	    <p>אם הינך משתמש באנטרנט אקספלורר גרסה 6 ומעלה עליך לאפשר התקנת הרכיב כפי שמופיע בחלקו העליון של הדף, מתחת לסרגל הכלים:</p>
	    <p style="padding: 4px"><!--<img src="http://212.235.45.33/images/infobar.png">--></p>
	    <p>במידה והודעה זו הופיע עליך להקיש עליה באמצעות לחצן העכבר ולבחור באפשרות להתקנה, <i>Install ActiveX Control...</i></p>
	    <p><b>להתקנה ידנית של הרכיב </b><a href="http://212.235.45.33/plug-in/ie_printsetup/smsx.exe">MeadCo's ScriptX</a></p>
      <p style="padding: 4px">לביטול ההתקנה והגדרת ההדפסה בצורה ידנית <b><a onclick="setInstallStyles(true)"  style="color:red">התעלם...</a></b></p>
    </div>
    <table id=toc dir="rtl" border="0" cellpadding="0" cellspacing="0">
    <tr><td>
        <table dir="rtl" border="0" cellpadding="0" cellspacing="0">
          <tr id="Title" height="27">
            <td colspan="2"  align="right" style="padding-bottom: 3">
              <table id="tblTitle"  border="0" cellpadding="0" cellspacing="0">
                <tr>
                  <td class="Title" align="right"> <%=title %></td>
                  <td class="Title" align="left"><%=TitleName %></td>
                </tr>
              </table>
            </td>
          </tr>
          <tr>
            <td id="LegendOld"></td>
            <td style="border: 1px solid black;padding: 0"  align="center">
              <table dir="rtl" border="0" cellpadding="0" cellspacing="0">
                <tr>
                  <td id="Map-right-td" rowspan="3"></td>
                  <td id="Map-top-td"></td>
                  <td id="Map-left-td" rowspan="3"></td>
                </tr>
                <tr><td id="Map-td"></td></tr>
                <tr><td id="Map-bottom-td"></td></tr>
             </table>
            </td>
         </tr>
          <tr>
            <td colspan="2" id="envp0" class="coord" align="left"></td>
          </tr>
        </table>
    </td></tr>
    <tr><td>   
        <table id="footerTable" width="100%%" dir="rtl" border="0" cellpadding="0" cellspacing="0" style="font-family:Arial; font-size: 11px">
          <tr id="ScaleAndArrow">
            <td id="Logo" align="right" valign="bottom" style="white-space:nowrap"></td>
            <td id="Scale" align="center" valign="top"></td>
            <td id="MinimapContainer" width="150px" valign="center" style="display:none;"><div id="MinimapTitle">מפת התמצאות</div><div id="Minimap"></div></td>
			<td id="Legend" align="left" valign="top"></td>
            <td id="Arrow" width="50px" align="center" valign="top"></td>
          </tr>
        </table>
    </td></tr>
    </table>
  </body>
  </html>